package com.bwie.controller;

import com.bwie.common.domain.User;
import com.bwie.common.domain.request.UserLoginReq;
import com.bwie.common.domain.response.UserLoginResp;
import com.bwie.common.result.Result;
import com.bwie.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.OutputStream;

/**
 * @className: AuthController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 李明
 * @date: 2025/10/22 9:49
 */
@RestController
@CrossOrigin
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 生成图片验证码
     */
    @GetMapping("getImageCode")
    public void getImageCode(OutputStream outputStream){
       authService.getImageCode(outputStream);
    }

    /**
     * 账号登录
     */
    @PostMapping("doLogin")
    public Result<UserLoginResp> doLogin(@RequestBody UserLoginReq userLoginReq){
        UserLoginResp userLoginResp = authService.doLogin(userLoginReq);
        return Result.success(userLoginResp);
    }


    /**
     * 通过手机号发送验证码
     */
    @GetMapping("sendCode/{phone}")
    public Result sendCode(@PathVariable("phone") String phone){
        authService.sendCode(phone);
        return Result.success();
    }

    /**
     * 手机号登录
     */
    @PostMapping("doLoginByPhone")
    public Result<UserLoginResp> doLoginByPhone(@RequestBody UserLoginReq userLoginReq){
        UserLoginResp userLoginResp = authService.doLoginByPhone(userLoginReq);
        return Result.success(userLoginResp);
    }


    /**
     * 获取登录人信息
     * @return
     */
    @GetMapping("getUserInfo")
    public Result<User> getUserInfo(){
        User user = authService.getUserInfo();
        return Result.success(user);
    }

}
